package com.xiaoxin.errorDemo.schedule;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 定时统计订单,金额
 */
@Component
class VideoOrderTask {
    // ↓任务结束之后才开始计时
    // @Scheduled(fixedDelay = 4000)
    // ↓每过一定时间后立马执行
    @Scheduled(fixedRate = 4000)
    //@Scheduled(cron = "*/1 * * * * *")
    public void sum() {
        //正常的是从数据库中查询
        System.out.println(LocalDateTime.now() + " 当前交易额=" + Math.random());
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
